#include <iostream>
#include <string>

#include "contacts.pb.h"

int main()
{
    std::string str;

    {
        // 创建对象
        contacts::people_info people;
        people.set_name("张三");
        people.set_age(20);
        
        // 序列化
        if (!people.SerializeToString(&str))
            std::cout << "serializer err" << std::endl;
        std::cout << "serializer result: " << std::endl;
        std::cout << str << std::endl;
    }

    {
        // 反序列出对象
        contacts::people_info people;
        if (!people.ParseFromString(str))
            std::cout << "parse err" << std::endl;
        std::cout << "parser result: " << std::endl;
        std::cout << "people name: " << people.name() << ' ';
        std::cout << "people age: " << people.age() << std::endl;
        
    }

    return 0;
}